package com.infocollect.project.grant.controller;

import java.util.ArrayList;
import java.util.List;

import com.infocollect.project.grant.domain.GrFamiliesExampointDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.infocollect.framework.aspectj.lang.annotation.Log;
import com.infocollect.framework.aspectj.lang.enums.BusinessType;
import com.infocollect.project.grant.domain.GrFamiliesExampoint;
import com.infocollect.project.grant.service.IGrFamiliesExampointService;
import com.infocollect.framework.web.controller.BaseController;
import com.infocollect.framework.web.domain.AjaxResult;
import com.infocollect.common.utils.poi.ExcelUtil;
import com.infocollect.framework.web.page.TableDataInfo;

/**
 * 科类考点关联Controller
 * 
 * @author infocollect
 * @date 2022-05-14
 */
@RestController
@RequestMapping("/grant/familiesexampoint")
public class GrFamiliesExampointController extends BaseController
{
    @Autowired
    private IGrFamiliesExampointService grFamiliesExampointService;

    /**
     * 查询科类考点关联列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GrFamiliesExampointDto grFamiliesExampointDto)
    {
        startPage();
        if(grFamiliesExampointDto.getGranttypeId()==null){
            return getDataTable(new ArrayList<GrFamiliesExampointDto>());
        }
        List<GrFamiliesExampointDto> list = grFamiliesExampointService.selectGrFamiliesExampointList(grFamiliesExampointDto);
        return getDataTable(list);
    }

    /**
     * 导出科类考点关联列表
     */
    @PreAuthorize("@ss.hasPermi('grant:familiesexampoint:export')")
    @Log(title = "科类考点关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GrFamiliesExampointDto grFamiliesExampointDto)
    {
        List<GrFamiliesExampointDto> list = grFamiliesExampointService.selectGrFamiliesExampointList(grFamiliesExampointDto);
        ExcelUtil<GrFamiliesExampointDto> util = new ExcelUtil<GrFamiliesExampointDto>(GrFamiliesExampointDto.class);
        return util.exportExcel(list, "familiesexampoint");
    }

    /**
     * 获取科类考点关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('grant:familiesexampoint:query')")
    @GetMapping(value = "/{examPointId}")
    public AjaxResult getInfo(@PathVariable("examPointId") Long examPointId)
    {
        return AjaxResult.success(grFamiliesExampointService.selectGrFamiliesExampointById(examPointId));
    }

    /**
     * 新增科类考点关联
     */
    @PreAuthorize("@ss.hasPermi('grant:familiesexampoint:add')")
    @Log(title = "科类考点关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrFamiliesExampointDto grFamiliesExampointDto)
    {
//        return toAjax(grFamiliesExampointService.insertGrFamiliesExampoint(grFamiliesExampoint));
        return grFamiliesExampointService.saveExampointFamilies(grFamiliesExampointDto);
    }

    /**
     * 修改科类考点关联
     */
    @PreAuthorize("@ss.hasPermi('grant:familiesexampoint:edit')")
    @Log(title = "科类考点关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrFamiliesExampoint grFamiliesExampoint)
    {
        return toAjax(grFamiliesExampointService.updateGrFamiliesExampoint(grFamiliesExampoint));
    }

    /**
     * 删除科类考点关联
     */
    @PreAuthorize("@ss.hasPermi('grant:familiesexampoint:remove')")
    @Log(title = "科类考点关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examPointIds}")
    public AjaxResult remove(@PathVariable Long[] examPointIds)
    {
        return toAjax(grFamiliesExampointService.deleteGrFamiliesExampointByIds(examPointIds));
    }

    @GetMapping("/getFamiliesSelectList")
    public AjaxResult getFamiliesSelectList(GrFamiliesExampointDto grFamiliesExampointDto){
//        if(grFamiliesExampointDto.getParentId()==null){
//            return AjaxResult.error("请先选择科类！");
//        }
        List<GrFamiliesExampointDto> familiesExampointDtoList = grFamiliesExampointService.getFamiliesSelectList(grFamiliesExampointDto);
        return AjaxResult.success(familiesExampointDtoList);
    }
}
